package cn.mugutu.finance.domain.system;

import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Date;

/**
 * 实体基类
 *
 * @author ganbo E-mail:bo.gan@56qq.com
 * @since 2017-11-30 12:38
 */
@MappedSuperclass
@Data
public class BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    private Long id;

    private Date createTime;
    private Date updateTime;


    /**
     * 覆盖toString方法，目的显示所有JavaBean的属性值，省略写很多的getXxx的方法
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (!getClass().equals(obj.getClass())) {
            return false;
        }
        BaseEntity rhs = (BaseEntity) obj;
        return this.id == null ? false : this.id.equals(rhs.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
